<template>
  <div>
    <!-- 中间走马灯 -->
    <div>
      <el-carousel :interval="4000" type="card" height="280px">
        <el-carousel-item v-for="(item,index) in imgList" :key="index">
          <img :src="item.url" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <br />

    <!-- 公告 -->
    <el-alert
      class="new-notice"
      title="最新公告"
      type="warning"
      effect="dark"
      show-icon
      :closable="isCloseNewNotice"
    ></el-alert>
    <el-card shadow="hover" class="notice-card">
      <el-timeline>
        <el-timeline-item
          v-for="(item,index) in noticeList "
          :key="index"
          :timestamp="item.createTime"
          placement="top"
        >
          <el-card>
            <el-link @click="toNotice(item.id)">
              {{item.title}}
              <i class="el-icon-view el-icon--right"></i>
            </el-link>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Welcome",
  data() {
    return {
      // 轮播图
      imgList: [
        { url: require("../../assets/img/img02.png") },
        { url: require("../../assets/img/img04.png") },
        { url: require("../../assets/img/img03.png") },
        { url: require("../../assets/img/img01.png") },
        { url: require("../../assets/img/img05.png") }
      ],
      // 是否显示公告关闭按钮
      isCloseNewNotice: false,
      noticeList: []
    };
  },
  methods: {
    getLatestNotice() {
      this.$http
        .get("/notice/noAuthorize/latest")
        .then(resp => {
          let { data, code, msg } = resp.data;
          if (code == 1) {
            this.noticeList = data.noticeList;
          }
        })
        .catch(resp => {});
    },
    // 跳转到公告页面
    toNotice(id) {
      this.$router.push("noticeDetails/?noticeId=" + id);
    }
  },
  created() {
    this.getLatestNotice();
  }
};
</script>

<style scoped lang ='less'>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.el-carousel__container {
  border-radius: 15px;
}

.el-timeline-item {
  margin-top: 20px;
}
.notice-card {
  width: 900px;
  margin-left: 30px;
  .is-always-shadow {
    margin-right: 60px;
  }
}

.el-card {
  border-radius: 30px;
}
</style>